package com.qd.p2p.web.action.notify.redenvelope;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.springframework.beans.factory.annotation.Qualifier;

import com.qd.p2p.web.action.notify.TradeNotifyBaseAction;
import com.qd.p2p.web.action.notify.TradeNotifyValueEvent;
import com.qdlc.p2p.biz.service.CollectPayService;
import com.qdlc.p2p.common.constant.NotifyUrl;

/**
 * 红包兑换 - 代付 回调通知
 *
 * @author wuaj 2016-01-21
 */
public class NotifyPayAction extends TradeNotifyBaseAction {

    /** 业务名 */
    private final static String BUSINESS_NAME = "红包兑换";

    /** 业务处理名 */
    private final static String PROCESS_NAME = "代付";

    /** 代付业务处理 */
    @Resource
    @Qualifier("redEnvelopePayService")
    private CollectPayService redEnvelopePayService;

    /**
     * 代付回调处理
     */
    @Override
    @Action(value = NotifyUrl.RED_ENVELOPE_NOTIFY_PAY_URL)
    public void doAction() {
        actionHandle();
    }

    @Override
    public String getBusinessName() {
        return BUSINESS_NAME;
    }

    @Override
    public String getProcessName() {
        return PROCESS_NAME;
    }

    /**
     * 完成状态 业务处理
     */
    @Override
    public void finishHandle(TradeNotifyValueEvent event) {
        redEnvelopePayService.tradeFinish(event.getTppTradeLog(), event.getDepositStatus(), event.getDepositAmount());
    }

    /**
     * 成功状态 业务处理
     */
    @Override
    public void successHandle(TradeNotifyValueEvent event) {
        redEnvelopePayService.tradeSuccess(event.getTppTradeLog(), event.getDepositStatus());
    }

    /**
     * 失败状态 业务处理
     */
    @Override
    public void failHandle(TradeNotifyValueEvent event) {
        redEnvelopePayService.tradeFail(event.getTppTradeLog(), event.getDepositStatus());
    }
}
